<% title "Committers to #{@repository.full_name} - Libraries.io" %>

<div class="row">
  <div class='col-sm-12'>
    <h1>
      <%= fa_icon 'keyboard-o' %>
      Committers to
      <%= link_to @repository.full_name, repository_path(@repository.to_param) %></h1>
  </div>
</div>
<hr>
<div class="row">
  <div class="col-sm-8">
    <% if @contributions.any? %>
      <% @contributions.each do |contribution| %>
        <% user = contribution.repository_user %>
        <% next if user.nil? %>
        <% width = contribution.count/@top_count.to_f*100 %>
        <div class="contributor-bar">
          <%= link_to image_tag(user.avatar_url(100), width: 50, height: 50, alt: user), user_path(user.to_param) %>
          <div class="contribution-bar" style='background: linear-gradient(90deg, #f5f5f5 <%= width.round(2) %>%, #FFFFFF <%= width.round(2) %>%);'>
            <h4>
              <%= link_to user, user_path(user.to_param) %>
              <% if user.name.present? && user.name.downcase != user.login.downcase %>
                <small>
                  <%= user.login %>
                </small>
              <% end %>
            </h4>
            <p>
              <small class='text-muted'>
                <%= link_to "#{number_to_human(contribution.count)} #{'commit'.pluralize(contribution.count)}", @repository.commits_url(user.login) %>
                - <%= (contribution.count/@total.to_f*100).round(Math.log10(@contributions.total_entries)) %>%
              </small>
            </p>
          </div>
        </div>
      <% end %>
      <%= will_paginate @contributions, page_links: false %>
    <% else %>
      <p>
        No contributors found, go back to <%= link_to @repository.full_name, repository_path(@repository.to_param) %>.
      </p>
    <% end %>
  </div>
  <div class="col-sm-4">
    <% if @contributions.any? %>
      <p class="h4">Total commits:</p>
      <p class="h1"><%= number_to_human @total %></p>
      <hr/>
      <p class="h4">Total contributors:</p>
      <p class="h1"><%= number_to_human @contributions.total_entries %></p>
      <hr>
      <p class="h4">Average commits:</p>
      <% days = (Time.now - @repository.created_at)/1.day %>
      <p class="h1"><%= ((@total/days.to_f)).round(2) %> per day</p>
      <small class='tip' title='<%= number_to_human days %> days since repo creation'>Across <%= distance_of_time_in_words(Time.now, @repository.created_at) %></small>
    <% end %>
    <% if @any_hidden %>
      <hr>
      <p>
        <small class='text-muted'>
          <%= fa_icon 'exclamation-circle' %>
          Some users are hidden from this list.
        </small>
      </p>
    <% end %>
  </div>
</div>
